#define _CRT_SECURE_NO_WARNINGS

class cmp
{
public:
    bool operator()(const string& s1, const string& s2)
    {
        return s1.size() < s2.size();
    }
};
class Solution {
public:
    string longestCommonPrefix(vector<string>& strs) {
        if (strs.size() == 1) return strs[0];
        sort(strs.begin(), strs.end(), cmp());
        int start = 0;
        int bre = 1;
        while (start < strs[0].size())
        {
            for (int i = 0; i < strs.size() - 1; i++)
            {
                int j = i + 1;
                if (strs[i][start] != strs[j][start])
                {
                    bre = 0;
                    break;
                }
            }
            if (!bre) break;
            start++;
        }
        return strs[0].substr(0, start);
    }
};